<template>
  <a-modal
    title="任务详情"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    @ok="handleCancel">

    <a-spin :spinning="confirmLoading">

      <a-form-item
        label="任务类型"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        has-feedback=""
      >
        <a-input :disabled="true" :value="taskTypeFilter(record.taskType)"/>
      </a-form-item>

      <a-form-item
        label="下发时间"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        has-feedback=""
      >
        <a-input v-model="record.issuedTime" :disabled="true"/>
      </a-form-item>

      <a-form-item
        label="附加参数"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        has-feedback=""
      >
        <a-textarea disabled :rows="3" v-model="record.taskParams"/>
      </a-form-item>

      <a-form-item
        label="响应时间"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        has-feedback=""
      >
        <a-input v-model="record.responseTime" :disabled="true"/>
      </a-form-item>
      <a-form-item
        label="响应结果"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        has-feedback=""
      >
        <a-textarea v-model="record.response_result" :disabled="true" :rows="3"/>
      </a-form-item>

    </a-spin>
  </a-modal>
</template>

<script>
  import { sysDictTypeDropDown } from '@/api/modular/system/dictManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        record: {},
        gatewayTaskTypeList: []
      }
    },

    created () {
      this.getGatewayTaskTypeList()
    },

    methods: {
      getGatewayTaskTypeList () {
        sysDictTypeDropDown({ code: 'gateway_task_type' }).then((res) => {
          if (res.success) {
            this.gatewayTaskTypeList = res.data
          }
        })
      },
      taskTypeFilter (record) {
        let str = ''
        this.gatewayTaskTypeList.forEach(item => {
          if (record === item.code) {
            str = item.value
          }
        })
        return str
      },
      edit (record) {
        this.visible = true
        this.record = record
      },
      handleCancel () {
        this.visible = false
        this.record = {}
      }
    }
  }
</script>
